package com.lavegue.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.commons.lang.time.DateUtils;

/**
 * 
 * @author luoweibin
 * @date Oct 19, 2009
 * @description
 * 
 */
public class DateTimeUtil {

	/**
	 * 把日期格式化成 年-月-日 时:分:秒
	 * @param date
	 * @return
	 */
	public static String formatLong(Date date) {
		DateFormat formater = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return formater.format(date);
	}
	
	public static String formatShort(Date date) {
		DateFormat formater = new SimpleDateFormat("yyyy-MM-dd");
		return formater.format(date);
	}
	
	/**
	 * 获取指定日期最开始的时间 时.分.秒.毫秒 置为0
	 * @param date
	 * @return
	 */
	public static Date getDateStart(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		
		cal.set(cal.HOUR_OF_DAY, 0);
		cal.set(cal.MINUTE, 0);
		cal.set(cal.SECOND, 0);
		cal.set(cal.MILLISECOND, 0);
		return cal.getTime();
	}
	
	/**
	 * 获取指定日期最后一毫秒的时间
	 * @param date
	 * @return
	 */
	public static Date getDateEnd(Date date) {
		Calendar cal = Calendar.getInstance();
		cal.setTime(date);
		
		cal.set(cal.HOUR_OF_DAY, 12);
		cal.set(cal.MINUTE, 59);
		cal.set(cal.SECOND, 59);
		cal.set(cal.MILLISECOND, 999);
		return cal.getTime();
	}
	
	
	
	public static void main(String[] args) {
		System.out.println(DateTimeUtil.formatLong(DateTimeUtil.getDateEnd(new Date())));
	}
}
